package com.lza.phone.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lza.phone.entity.Performance;
import com.lza.phone.entity.Soc;
import com.lza.phone.entity.connectEntity.SocAndPer;
import com.lza.phone.service.PerformanceService;
import com.lza.phone.service.SocService;
import com.lza.response.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李钊澳
 * @since 2021-08-28
 */
@RestController
@RequestMapping("/soc")
public class SocController {
    @Autowired
    SocService socService;
    @ApiOperation("cpu模糊查询")
    @ApiOperationSupport(author = "澳神弱爆")
    @PostMapping("/findCpu/{socName}")
    public Result findCpu(@PathVariable("socName") String socName){
        QueryWrapper<Soc> socQueryWrapper=new QueryWrapper<>();
       socQueryWrapper.like("socName",socName);
        List<Soc> soc = socService.list(socQueryWrapper);//可能查找有多条结果
        if(soc.isEmpty()) {
            return Result.error().getMessage("没有该cpu,请尝试更改其他cpu名字");
        }else {
            return Result.ok().getData("查找该soc成功", soc);
        }
    }

    @ApiOperation("cpu性能排行榜")
    @ApiOperationSupport(author = "澳神弱爆")
    @GetMapping("cpuByPer")
    public Result cpuByPer(){
        List<SocAndPer> socAndPer = socService.cpuByPer();
        return Result.ok().getData("嘿嘿", socAndPer);
    }
}

